/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * POS_ClerkDiscount.java
 *
 * Created on Apr 4, 2011, 2:33:42 PM
 */

package POS_Source;

import Cart.Cart;
import Exception.KwickKioskDBException;
import POS_Controller.POSController;
import Session.POS_SessionManager;
import Utilities.MoneyFormatter;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * this class renders clerk discount view
 * @author edaype
 * @see POS_Source
 */
public class POS_ClerkDiscount extends javax.swing.JPanel {

    private Cart cart;
    private POSController controller;
    private MoneyFormatter moneyFormatter;

    /**
     * constructor for this class
     * @param control
     */
    public POS_ClerkDiscount(POSController control) {
        initComponents();
        controller = control;
        this.cart = control.getSessionManager().getCart();
        moneyFormatter = new MoneyFormatter();
        setTotals();
    }
/**
 * this method adds text to field
 * @param number
 */
    private void addTextToField(String number){
        AmountField.setText(AmountField.getText() + number);
    }

    /**
     * this method updates dynamic receipt view
     */
    private void setTotals(){
        StoreCardDiscountAmount.setText(moneyFormatter.format(cart.getStoreCardDiscount()));
        DiscountAmount.setText(moneyFormatter.format(cart.getTotalDiscount()));
        SubTotalAmount.setText(moneyFormatter.format(cart.getSubtotal()));
        TaxAmount.setText(moneyFormatter.format(cart.getTaxAmount()));
        TotalAmount.setText(moneyFormatter.format(cart.getTotal()));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ButtonLayout = new javax.swing.JPanel();
        SubmitButton = new javax.swing.JButton();
        TitleLabel = new javax.swing.JLabel();
        ErrorLabel = new javax.swing.JLabel();
        InputPanel = new javax.swing.JPanel();
        NewDiscountLabel = new javax.swing.JLabel();
        AmountField = new javax.swing.JTextField();
        SubTotalOut = new javax.swing.JLabel();
        KeypadPanel = new javax.swing.JPanel();
        OneButton = new javax.swing.JButton();
        TwoButton = new javax.swing.JButton();
        ThreeButton = new javax.swing.JButton();
        SixButton = new javax.swing.JButton();
        FiveButton = new javax.swing.JButton();
        FourButton = new javax.swing.JButton();
        NineButton = new javax.swing.JButton();
        EightButton = new javax.swing.JButton();
        SevenButton = new javax.swing.JButton();
        ClearButton = new javax.swing.JButton();
        ZeroButton = new javax.swing.JButton();
        EraseButton = new javax.swing.JButton();
        OrderPanel = new javax.swing.JPanel();
        OrderLabel = new javax.swing.JLabel();
        StoreCardLabel = new javax.swing.JLabel();
        StoreCardDiscountAmount = new javax.swing.JLabel();
        TotalDiscountLabel = new javax.swing.JLabel();
        SubtotalLabel = new javax.swing.JLabel();
        TaxLabel = new javax.swing.JLabel();
        DiscountAmount = new javax.swing.JLabel();
        DivisionLabel = new javax.swing.JLabel();
        TotalLabel = new javax.swing.JLabel();
        SubTotalAmount = new javax.swing.JLabel();
        TaxAmount = new javax.swing.JLabel();
        TotalAmount = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        ButtonLayout.setBackground(new java.awt.Color(255, 255, 255));

        SubmitButton.setFont(new java.awt.Font("Tahoma", 0, 18));
        SubmitButton.setText("Submit");
        SubmitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SubmitButtonActionPerformed(evt);
            }
        });

        TitleLabel.setFont(new java.awt.Font("Copperplate Gothic Bold", 2, 60));
        TitleLabel.setText("Add Discount");

        ErrorLabel.setFont(new java.awt.Font("Tahoma", 3, 24));
        ErrorLabel.setForeground(new java.awt.Color(255, 0, 0));
        ErrorLabel.setText(" ");

        javax.swing.GroupLayout ButtonLayoutLayout = new javax.swing.GroupLayout(ButtonLayout);
        ButtonLayout.setLayout(ButtonLayoutLayout);
        ButtonLayoutLayout.setHorizontalGroup(
            ButtonLayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ButtonLayoutLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ButtonLayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ErrorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 531, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(ButtonLayoutLayout.createSequentialGroup()
                        .addComponent(TitleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 478, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 157, Short.MAX_VALUE)
                        .addComponent(SubmitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        ButtonLayoutLayout.setVerticalGroup(
            ButtonLayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ButtonLayoutLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ErrorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addGroup(ButtonLayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(TitleLabel)
                    .addComponent(SubmitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        InputPanel.setBackground(new java.awt.Color(255, 255, 255));
        InputPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        NewDiscountLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        NewDiscountLabel.setText("Discount:");

        AmountField.setFont(new java.awt.Font("Tahoma", 0, 18));

        SubTotalOut.setFont(new java.awt.Font("Tahoma", 0, 18));
        SubTotalOut.setText("%");

        KeypadPanel.setBackground(new java.awt.Color(255, 255, 255));

        OneButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        OneButton.setText("1");
        OneButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OneButtonActionPerformed(evt);
            }
        });

        TwoButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        TwoButton.setText("2");
        TwoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TwoButtonActionPerformed(evt);
            }
        });

        ThreeButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        ThreeButton.setText("3");
        ThreeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ThreeButtonActionPerformed(evt);
            }
        });

        SixButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        SixButton.setText("6");
        SixButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SixButtonActionPerformed(evt);
            }
        });

        FiveButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        FiveButton.setText("5");
        FiveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FiveButtonActionPerformed(evt);
            }
        });

        FourButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        FourButton.setText("4");
        FourButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FourButtonActionPerformed(evt);
            }
        });

        NineButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        NineButton.setText("9");
        NineButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NineButtonActionPerformed(evt);
            }
        });

        EightButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        EightButton.setText("8");
        EightButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EightButtonActionPerformed(evt);
            }
        });

        SevenButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        SevenButton.setText("7");
        SevenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SevenButtonActionPerformed(evt);
            }
        });

        ClearButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        ClearButton.setText("C");
        ClearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearButtonActionPerformed(evt);
            }
        });

        ZeroButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        ZeroButton.setText("0");
        ZeroButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ZeroButtonActionPerformed(evt);
            }
        });

        EraseButton.setFont(new java.awt.Font("Tahoma", 0, 24));
        EraseButton.setText("<-");
        EraseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EraseButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout KeypadPanelLayout = new javax.swing.GroupLayout(KeypadPanel);
        KeypadPanel.setLayout(KeypadPanelLayout);
        KeypadPanelLayout.setHorizontalGroup(
            KeypadPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(KeypadPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(KeypadPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(KeypadPanelLayout.createSequentialGroup()
                        .addComponent(OneButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TwoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ThreeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(KeypadPanelLayout.createSequentialGroup()
                        .addComponent(FourButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(FiveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SixButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(KeypadPanelLayout.createSequentialGroup()
                        .addComponent(SevenButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(EightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(NineButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(KeypadPanelLayout.createSequentialGroup()
                        .addComponent(ClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ZeroButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(EraseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        KeypadPanelLayout.setVerticalGroup(
            KeypadPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(KeypadPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(KeypadPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(OneButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TwoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ThreeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(KeypadPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FourButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FiveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SixButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(KeypadPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SevenButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(EightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(NineButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(KeypadPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ClearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ZeroButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(EraseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout InputPanelLayout = new javax.swing.GroupLayout(InputPanel);
        InputPanel.setLayout(InputPanelLayout);
        InputPanelLayout.setHorizontalGroup(
            InputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(InputPanelLayout.createSequentialGroup()
                .addGroup(InputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(InputPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(KeypadPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(InputPanelLayout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(NewDiscountLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(AmountField, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SubTotalOut)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        InputPanelLayout.setVerticalGroup(
            InputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(InputPanelLayout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(InputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AmountField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SubTotalOut)
                    .addComponent(NewDiscountLabel))
                .addGap(18, 18, 18)
                .addComponent(KeypadPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(50, Short.MAX_VALUE))
        );

        OrderPanel.setBackground(new java.awt.Color(255, 255, 255));
        OrderPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        OrderLabel.setFont(new java.awt.Font("Tahoma", 0, 28));
        OrderLabel.setText("Current Order");

        StoreCardLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        StoreCardLabel.setText("Storecard Discount");

        StoreCardDiscountAmount.setFont(new java.awt.Font("Tahoma", 0, 14));
        StoreCardDiscountAmount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        StoreCardDiscountAmount.setText(" ");

        TotalDiscountLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        TotalDiscountLabel.setText("Total Discount");

        SubtotalLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        SubtotalLabel.setText("Subtotal");

        TaxLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        TaxLabel.setText("Tax");

        DiscountAmount.setFont(new java.awt.Font("Tahoma", 0, 14));
        DiscountAmount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        DiscountAmount.setText(" ");

        DivisionLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
        DivisionLabel.setText("________________________________");

        TotalLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        TotalLabel.setText("Total");

        SubTotalAmount.setFont(new java.awt.Font("Tahoma", 0, 14));
        SubTotalAmount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        SubTotalAmount.setText(" ");

        TaxAmount.setFont(new java.awt.Font("Tahoma", 0, 14));
        TaxAmount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        TaxAmount.setText(" ");

        TotalAmount.setFont(new java.awt.Font("Tahoma", 0, 18));
        TotalAmount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        TotalAmount.setText(" ");

        javax.swing.GroupLayout OrderPanelLayout = new javax.swing.GroupLayout(OrderPanel);
        OrderPanel.setLayout(OrderPanelLayout);
        OrderPanelLayout.setHorizontalGroup(
            OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(OrderPanelLayout.createSequentialGroup()
                .addContainerGap(94, Short.MAX_VALUE)
                .addComponent(OrderLabel)
                .addContainerGap(85, Short.MAX_VALUE))
            .addGroup(OrderPanelLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(OrderPanelLayout.createSequentialGroup()
                        .addComponent(TotalLabel)
                        .addGap(18, 18, 18)
                        .addComponent(TotalAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(OrderPanelLayout.createSequentialGroup()
                            .addGroup(OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(TaxLabel)
                                .addComponent(SubtotalLabel)
                                .addComponent(TotalDiscountLabel)
                                .addComponent(StoreCardLabel))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                            .addGroup(OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(SubTotalAmount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(TaxAmount, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                                .addComponent(DiscountAmount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(StoreCardDiscountAmount, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addComponent(DivisionLabel)))
                .addGap(60, 60, 60))
        );
        OrderPanelLayout.setVerticalGroup(
            OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(OrderPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(OrderLabel)
                .addGap(101, 101, 101)
                .addGroup(OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(StoreCardLabel)
                    .addComponent(StoreCardDiscountAmount))
                .addGap(18, 18, 18)
                .addGroup(OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TotalDiscountLabel)
                    .addComponent(DiscountAmount))
                .addGap(18, 18, 18)
                .addGroup(OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SubtotalLabel)
                    .addComponent(SubTotalAmount))
                .addGap(18, 18, 18)
                .addGroup(OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TaxLabel)
                    .addComponent(TaxAmount))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(DivisionLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(OrderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TotalLabel)
                    .addComponent(TotalAmount))
                .addGap(68, 68, 68))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(OrderPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(85, 85, 85)
                        .addComponent(InputPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(ButtonLayout, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(InputPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(OrderPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE))
                .addGap(26, 26, 26)
                .addComponent(ButtonLayout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(140, 140, 140))
        );
    }// </editor-fold>//GEN-END:initComponents
/**
 * this method handles button press event
 * @param evt
 */
    private void OneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OneButtonActionPerformed
        addTextToField("1");
}//GEN-LAST:event_OneButtonActionPerformed
/**
 * this method handles button press event
 * @param evt
 */
    private void TwoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TwoButtonActionPerformed
        addTextToField("2");
}//GEN-LAST:event_TwoButtonActionPerformed
/**
 * this method handles button press event
 * @param evt
 */
    private void ThreeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ThreeButtonActionPerformed
        addTextToField("3");
}//GEN-LAST:event_ThreeButtonActionPerformed
/**
 * this method handles button press event
 * @param evt
 */
    private void SixButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SixButtonActionPerformed
        addTextToField("6");
}//GEN-LAST:event_SixButtonActionPerformed
/**
 * this method handles button press event
 * @param evt
 */
    private void FiveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FiveButtonActionPerformed
        addTextToField("5");
}//GEN-LAST:event_FiveButtonActionPerformed
/**
 * this method handles button press event
 * @param evt
 */
    private void FourButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FourButtonActionPerformed
        addTextToField("4");
}//GEN-LAST:event_FourButtonActionPerformed
/**
 * this method handles button press event
 * @param evt
 */
    private void NineButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NineButtonActionPerformed
        addTextToField("9");
}//GEN-LAST:event_NineButtonActionPerformed
/**
 * this method handles button press event
 * @param evt
 */
    private void EightButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EightButtonActionPerformed
        addTextToField("8");
}//GEN-LAST:event_EightButtonActionPerformed
/**
 * this method handles button press event
 * @param evt
 */
    private void SevenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SevenButtonActionPerformed
        addTextToField("7");
}//GEN-LAST:event_SevenButtonActionPerformed
/**
 * this method handles clear button press event
 * @param evt
 */
    private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearButtonActionPerformed
        AmountField.setText("");
}//GEN-LAST:event_ClearButtonActionPerformed
/**
 * this method handles button press event
 * @param evt
 */
    private void ZeroButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ZeroButtonActionPerformed
        addTextToField("0");
}//GEN-LAST:event_ZeroButtonActionPerformed
/**
 * this method handles erase button press event
 * @param evt
 */
    private void EraseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EraseButtonActionPerformed
        if (AmountField.getText().length() > 0)
            AmountField.setText(AmountField.getText().substring(0, AmountField.getText().length()-1));
}//GEN-LAST:event_EraseButtonActionPerformed
/**
 * this method handles submit button press event and it shows appropriate error message if
 * request fails 
 * @param evt
 */
    private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubmitButtonActionPerformed
        String amount = AmountField.getText();
        if(!amount.equals("")){
            int temp = Integer.parseInt(amount);
            if (temp >= 0 && temp <= 100){
                try {
                    double percentage = (double) temp / 100.00;
                    POS_SessionManager mgr = controller.getSessionManager();
                    System.out.println("percenage discount = " + percentage);
                    mgr.getCart().setOrderDiscount(percentage);
                    controller.getSessionManager().getCart().calculateTotals();
                    controller.CartScreen();
                } catch (KwickKioskDBException ex) {
                    Logger.getLogger(POS_ClerkDiscount.class.getName()).log(Level.SEVERE, null, ex);
                    controller.DatabaseDownScreen();
                }
            }
            else{
                ErrorLabel.setText("Invalid discount percentage. Please re-try.");
                AmountField.setText("");
        }
        }
        else{
            ErrorLabel.setText("No discount amount indicated.");
            AmountField.setText("");
        }
    }//GEN-LAST:event_SubmitButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AmountField;
    private javax.swing.JPanel ButtonLayout;
    private javax.swing.JButton ClearButton;
    private javax.swing.JLabel DiscountAmount;
    private javax.swing.JLabel DivisionLabel;
    private javax.swing.JButton EightButton;
    private javax.swing.JButton EraseButton;
    private javax.swing.JLabel ErrorLabel;
    private javax.swing.JButton FiveButton;
    private javax.swing.JButton FourButton;
    private javax.swing.JPanel InputPanel;
    private javax.swing.JPanel KeypadPanel;
    private javax.swing.JLabel NewDiscountLabel;
    private javax.swing.JButton NineButton;
    private javax.swing.JButton OneButton;
    private javax.swing.JLabel OrderLabel;
    private javax.swing.JPanel OrderPanel;
    private javax.swing.JButton SevenButton;
    private javax.swing.JButton SixButton;
    private javax.swing.JLabel StoreCardDiscountAmount;
    private javax.swing.JLabel StoreCardLabel;
    private javax.swing.JLabel SubTotalAmount;
    private javax.swing.JLabel SubTotalOut;
    private javax.swing.JButton SubmitButton;
    private javax.swing.JLabel SubtotalLabel;
    private javax.swing.JLabel TaxAmount;
    private javax.swing.JLabel TaxLabel;
    private javax.swing.JButton ThreeButton;
    private javax.swing.JLabel TitleLabel;
    private javax.swing.JLabel TotalAmount;
    private javax.swing.JLabel TotalDiscountLabel;
    private javax.swing.JLabel TotalLabel;
    private javax.swing.JButton TwoButton;
    private javax.swing.JButton ZeroButton;
    // End of variables declaration//GEN-END:variables

}
